<?php
namespace app\index\controller;

use app\index\model\FarmManager;
use think\Controller;
use think\Loader;

class Farm extends Controller
{
    private $user;
    public function __construct()
    {
        $this->user = new FarmManager();
    }

    public function index()
    {
       echoJson(1,"读取成功",$this->user->readAllFarm());
    }

    public function create(){

        $validate = Loader::validate('CreateFarm');
        if(!$validate->check($_GET)){
            if($validate->getError() !== true){
                echoJson(0, $validate->getError());
            }
        }

        echoJson(1, "添加成功",$this->user->createFarm($_GET));
    }

    public function read($id){
        echoJson(1,"读取成功",$this->user->readFarm($id));
    }

    public function delete($id){
        echoJson(1,"删除成功",$this->user->deleteFarm($id));
    }

    public function update($id){
        echoJson(1, "添加成功",$this->user->updateFarm($id,$_GET));
    }

}
